package com.study.experiment03.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author WS
 */
@WebServlet(name = "RedirectServlet", urlPatterns = "/experiment03/redirect")
public class RedirectServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("username");
        String pwd = request.getParameter("password");
        if (name.equals("admin") && pwd.equals("admin")) {
            //request.getRequestDispatcher("/welcome.html").forward(request,response);
            response.sendRedirect(request.getContextPath() + "/experiment03/welcome.html");
        } else {
            //request.getRequestDispatcher("/error.html").forward(request,response);
            response.sendRedirect(request.getContextPath() + "/experiment03/error.html");
        }

    }
}
